package com.shop.controller;


import com.shop.common.result.Result;
import com.shop.common.result.util.ResultModel;
import com.shop.config.interceptor.util.Auth;
import com.shop.service.ClientService;
import com.shop.vo.client.LoginVo;
import com.shop.vo.client.ObtainShortMessageVerificationVo;
import com.shop.vo.client.RegisterVo;
import com.shop.vo.client.ForgetPasswordVo;
import com.shop.vo.client.UpdateClientVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 客户表 前端控制器
 * </p>
 *
 * @author 靳 旺
 * @since 2020-12-16
 */
@Slf4j
@RestController
@Api(tags = "客户表前端控制器")
@RequestMapping("/client")
public class ClientController {

    @Autowired
    private ClientService clientService;

    @ResponseBody
    @PostMapping("/login")
    @ApiOperation(value = "用户登录",notes = "靳旺")
    public ResultModel login(@RequestBody @Valid LoginVo loginVo,BindingResult result) throws Exception {
        if (result.hasErrors()) return Result.errorResultModel(result.getAllErrors());
        return clientService.login(loginVo);
    }

    @ResponseBody
    @PostMapping("register")
    @ApiOperation(value = "用户注册",notes = "靳旺")
    public ResultModel register(@RequestBody @Valid RegisterVo registerVo, BindingResult result) throws Exception {
        if (result.hasErrors())  return Result.errorResultModel(result.getAllErrors());
        return clientService.register(registerVo);
    }

    @ResponseBody
    @PostMapping("updateClient")
    @ApiOperation(value = "修改客户信息",notes = "靳旺")
    public ResultModel updateClient(@RequestBody UpdateClientVo updateClientVo) throws Exception {
        return clientService.updateClient(updateClientVo);
    }

    @ResponseBody
    @PostMapping("getUserInfo")
    @ApiOperation(value = "查询客户信息",notes = "靳旺")
    public ResultModel getUserInfo() throws Exception {
        return clientService.getUserInfo();
    }

    @ResponseBody
    @PostMapping("getRole")
    @ApiOperation(value = "查询客户角色",notes = "靳旺")
    public ResultModel getRole() throws Exception {
        return clientService.getRole();
    }

    @ResponseBody
    @PostMapping("obtainShortMessageVerification")
    @ApiOperation(value = "发送注册短信验证",notes = "靳旺")
    public ResultModel obtainShortMessageVerification(@RequestBody ObtainShortMessageVerificationVo obtainShortMessageVerificationVo) throws Exception{
        return clientService.obtainShortMessageVerification(obtainShortMessageVerificationVo);
    }

    /**
     * 忘记密码发短信
     *
     */
    @ResponseBody
    @PostMapping("forgetSendMessage")
    @ApiOperation(value = "发送忘记密码短信验证",notes = "靳旺")
    public ResultModel forgetSendMessage(@RequestBody ObtainShortMessageVerificationVo obtainShortMessageVerificationVo) throws Exception{
        return clientService.forgetSendMessage(obtainShortMessageVerificationVo);
    }
    /**
     * 忘记密码
     *
     */
    @ResponseBody
    @PostMapping("forgetPassWord")
    @ApiOperation(value = "忘记密码",notes = "靳旺")
    public ResultModel obtainShortMessageVerification(@RequestBody @Valid ForgetPasswordVo forgetPasswordVo,BindingResult bindingResult) throws Exception{
        if (bindingResult.hasErrors())  return Result.errorResultModel(bindingResult.getAllErrors());
        return clientService.forgetPassWord(forgetPasswordVo);
    }

    @ResponseBody
    @PostMapping("openShopMessageVerification")
    @ApiOperation(value = "开店铺短信验证",notes = "靳旺")
    public ResultModel openShopMessageVerification(@RequestBody @Valid  ObtainShortMessageVerificationVo obtainShortMessageVerificationVo,BindingResult bindingResult) throws Exception{
        if (bindingResult.hasErrors())  return Result.errorResultModel(bindingResult.getAllErrors());
        return clientService.openShopMessageVerification(obtainShortMessageVerificationVo);
    }

}
